package main

import (
	"flag"
	"gitee.com/captials-team/ubdframe/src/common"
	"gitee.com/captials-team/ubdframe/src/pkg/gin_http"
	"gitee.com/captials-team/ubdframe/src/resource/swagger_ui/rapi_doc"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
	"net/http"
	"os"
)

func main() {
	addr := flag.String("server", "8080", "docs server listen addr")
	flag.Parse()

	r := gin.New()

	// use ginSwagger middleware to serve the API docs
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))                                                       //默认样式
	r.GET("/swagger_s1/*any", gin_http.SwaggerWrapHtmlHandle(rapi_doc.StaticFs), ginSwagger.WrapHandler(swaggerFiles.Handler)) //style1主题样式

	//默认
	r.GET("/", func(ctx *gin.Context) {
		ctx.Request.URL.Path = "/swagger_s1/index.html" //修改资源路径
		ctx.Redirect(http.StatusMovedPermanently, ctx.Request.URL.String())
		//下面这种方法跳转对 /swagger/index.html 渲染有问题
		//r.HandleContext(ctx) //跳转
	})

	common.ErrPanic(r.Run(":" + *addr))

	os.Exit(0)
}
